package bpm.domain.process;

import java.io.Serializable;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class LinkView implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public String processId;
	public String linkId;
	public String linkName;
	public Integer linkIndex;
	public String description;
	
	public String fromNodeId;
	public String fromNodeName;
	public String fromNodeTypeKey;
	public String fromNodeTaskType;
	public String fromNodeReference;
	public String fromNodeDescription;
	
	public String toNodeId;
	public String toNodeName;
	public String toNodeTypeKey;
	public String toNodeTaskType;
	public String toNodeReference;
	public String toNodeDescription;
	
	public LinkView() {}
	public LinkView(Link link) {
		if(link != null) {
			linkId = link.getLinkId();
			linkName = link.getLinkName();
			linkIndex = link.getLinkIndex();
			description = link.getDescription();
			
			Node from = null;
			if((from = link.getFrom()) != null) {
				if(from.getProcessDefinition() != null && processId == null) {
					processId = from.getProcessDefinition().getId();
				}
				fromNodeId = from.getId();
				fromNodeName = from.getName();
				fromNodeTypeKey = from.getType() == null ? null : from.getType().name();
				fromNodeTaskType = from.getTaskType() == null ? null : from.getTaskType().name();
				fromNodeReference = from.getReference();
				fromNodeDescription = from.getDescription();
			}
			
			Node to = null;
			if((to = link.getTo()) != null) {
				if(to.getProcessDefinition() != null && processId == null) {
					processId = to.getProcessDefinition().getId();
				}
				toNodeId = to.getId();
				toNodeName = to.getName();
				toNodeTypeKey = to.getType() == null ? null : to.getType().name();
				toNodeTaskType = to.getTaskType() == null ? null : to.getTaskType().name();
				toNodeReference = to.getReference();
				toNodeDescription = to.getDescription();
			}
		}
	}
}
